//UL Main Engine
//By:Desconocido

#include <oslib/oslib.h>
#include "collisions.h"
#include "animate.h"
#include "talking.h"

//PSP info
PSP_MODULE_INFO("Uncharted Lands", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

//Variables
OSL_MAP *overworld;
OSL_IMAGE *overworld_tileset, *michaelImg;

//classes
class RPG
{
      public:
             void displayCPU();
};
RPG game;

//**functions**
//RPG class functions
void RPG::displayCPU() {
	int ms4;
	ms4 = oslMeanBenchmarkTestEx(OSL_BENCH_GET, 4);
	ms4 *= 6;
	oslSetTextColor(RGB(255,255,255));
	oslSetBkColor(RGBA(255,255,255,0));
	oslPrintf_xy(0,0, "CPU: %i.%i%% (100 MHz)", ms4 / 1000, (ms4 % 1000) / 100);
}

//Main
int main()
{
    oslInit(0);
    oslInitGfx(OSL_PF_8888, 1);
    oslInitConsole();
    overworld_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551);
    michael.loadAnim("micheal.png",1,w,h);
    if (!overworld_tileset)
        oslDebug("you are missing Image Files");
    map.declareMap(overworld,overworld_tileset,overworld_map,64,64);
    map.loadMap();
    map.loadCollisions();

//Game Loop
    while (!osl_quit)
    {
        oslStartDrawing();
        oslClearScreen(RGB(0,0,0));
        oslReadKeys();
        map.drawMap();
        map.loadNonCollisions();
        player.boundaries();
        player.think();
        map.limitScroll();
        michael.drawAnim(x-currentMap->scrollX,y-currentMap->scrollY,DOWN,0);
        game.displayCPU();
        oslEndDrawing();
        oslSyncFrame();
    }
    oslEndGfx();
    oslQuit();
    return 0;
}
